<%@ page language="java" contentType="application/json; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"import="support.*, java.util.*, myclasses.*, java.sql.*, net.sf.json.JSONArray, net.sf.json.JSONObject"%>
    
<%String id = request.getParameter("id");
response.setContentType("application/json");
JSONObject jobject = new JSONObject();
JSONArray ja = new JSONArray();

try {
	Class.forName("org.postgresql.Driver");
} catch(Exception e) {
	out.println("org.postgresql.Driver Exception. ");
}

try {
	String serverName = "localhost:5432";
    String mydatabase = "ThirdBase";
    String url = "jdbc:postgresql://" + serverName + "/" + mydatabase; 
    String username = "SweetAss";
    String password = "1234";
    Connection conn = DriverManager.getConnection(url, username, password);
    
	Statement stmt = conn.createStatement();

	String degQuery = 	"SELECT gpa, major.name, year, university.name, title.name, month, applicant, degree.id  " +
						"FROM degree JOIN major ON degree.major = major.id " + 
		    				"JOIN title ON degree.title = title.id " +
		    				"JOIN university ON degree.university = university.id " +
		    			"WHERE degree.applicant = " + id;

	ResultSet rset = stmt.executeQuery(degQuery);
	
   	while(rset.next()) {
   		
   		JSONObject jo = new JSONObject();
   		jo.put("gpa", rset.getString(1));
   		jo.put("major", rset.getString(2));
   		jo.put("year", rset.getString(3));
   		jo.put("university", rset.getString(4));
   		jo.put("title", rset.getString(5));
   		jo.put("month", rset.getString(6));
   		jo.put("applicantId", rset.getString(7));
   		jo.put("degreeId", rset.getString(8));
   		ja.element(jo);
   	}
   	//jobject.put(ja);
   	
	out.println(ja);
	out.flush();
	
	rset.close();
	stmt.close();
	conn.close();

} catch(SQLException e) {
	e.printStackTrace();
	out.println("Connection exception.");
}
%>